<template>
	<view class="address-manage rf-row-wrapper">
		<view class="row b-b">
			<text class="tit">支付宝账号</text>
			<text>{{userInfo.alipay}}</text>
		</view>
		<view class="row b-b">
			<text class="tit">支付宝名称</text>
			<text>{{userInfo.alipayName}}</text>
		</view>
		<view class="row b-b">
			<text class="tit">可提现金额</text>
			<text>{{userInfo.purchareMoney}}元</text>
		</view>
		<view class="row b-b">
			<text class="tit">提现金额</text>
			<input
				class="input"
				type="digit"
				v-model="addressData.mobile"
				@blur="handleMobileChange"
				placeholder="输入提现金额"
				placeholder-class="placeholder"
			/>
		</view>

		<button
			class="add-btn"
			:class="'bg-' + themeColor.name"
			:disabled="btnLoading"
			:loading="btnLoading"
			@tap="confirm"
		>
			提现
		</button>

		<!--加载动画-->
		<rfLoading isFullScreen :active="loading"></rfLoading>
		<view class="flexc banner">
			<!-- <image v-for="(item, index) in banners" :key="index" :src="item.pic" mode="widthFix"></image> -->
			<swiper autoplay="true">
				<swiper-item
					v-for="(item, index) in banners"
					:key="index"
				>
					<view class="swiper-item" @tap="navTo2(item.url)">
						<image :src="item.pic" mode="aspectFill" />
					</view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
/**
 * @des 收货地址列表
 *
 * @author stav stavyan@qq.com
 * @date 2020-03-10 18:00
 * @copyright 2019
 */
import { addressCreate, addressUpdate, addressDetail, memberInfo } from '@/api/userInfo';
import rfPickRegions from '@/components/rf-pick-regions';

export default {
	components: {
		rfPickRegions
	},
	data() {
		return {
			addressData: {
				name: '',
				mobile: '',
				detailAddress: '',
				address_name: '请选择地址',
				address: '',
				isDefault: false,
				provinceId: '',
				cityId: '',
				countryId: ''
			},
			btnLoading: false,
			multiArray: [[], [], []],
			multiIndex: [0, 0, 0],
			loading: true,
			userInfo: {
				purchareMoney: 0
			},
			banners:[],
			type: 0
		};
	},
	onLoad(options) {
		if(options.type==2){
			this.type = 1;
		}
		//this.initData(options);
            this.$http.get(memberInfo).then(async r => {
                this.loading = false;
                let storeId = r.storeId;
                this.storeId = storeId + '';
				this.$http.get('/store/TStoreInfo/querystoreinfo?storeId='+storeId).then(res => {
					this.userInfo = res || {};
				});
				
			    // this.$refs.uqrcode.make({
		    	// 	size: 300,
		    	// 	text: r.storeId
		    	// })
		    	// .then(res => {
		    	// 	console.log(res)
		    	// 	this.codeUrl = res.tempFilePath;
		    	// })
            }).catch(() => {

                this.loading = false;
            });
			
			this.$http.get('/bannerList?storeId=0').then(r => {
				let banners = r || [];
				let arr = [];
				banners.forEach(item=>{
					if(item.orderCount==8){
						arr.push(item)
					}
				})
				this.banners = arr;
			});
	},
	methods: {
		// 获取选择的地区
		handleGetRegions(e) {
		console.log(e)
			this.addressData.provinceId = e.provinceId;
			this.addressData.cityId = e.cityId;
			this.addressData.countryId = e.countryId;
		},
		// 数据初始化
		async initData(options) {
			let title = '提现';
			if (options.type === 'edit') {
				title = '提现';
				await this.getAddressDetail(options.id);
			} else {
				setTimeout(() => {
					this.loading = false;
				}, 1 * 1000);
			}
			this.manageType = options.type;
			uni.setNavigationBarTitle({
				title
			});
		},
		// 获取收货地址
		async getAddressDetail(id) {
			await this.$http
				.get(`${addressDetail}`, {
					id
				})
				.then(async r => {
					this.addressData = await r;
					this.loading = false;
				})
				.catch(() => {
					this.loading = false;
				});
		},
		handlenameChange(e) {
			this.addressData.name = e.detail.value;
		},
		bindAddressDetailsChange(e) {
			this.addressData.detailAddress = e.detail.value;
		},
		handleMobileChange(e) {
			this.addressData.mobile = e.detail.value;
		},
		switchChange(e) {
			this.addressData.isDefault = e.detail.value;
		},
		// 提交
		confirm() {
			let data = this.addressData;
			if (!data.mobile) {
				this.$mHelper.toast('请填写提现金额');
				return;
			}
			// if(parseInt(data.mobile) > this.userInfo.balance){
			// 	this.$mHelper.toast('可提现金额不足');
			// 	return;
			// }
			this.btnLoading = true;
			this.handleAddressUpdate(data);
		},
		async handleAddressUpdate(data) {
			await this.$http
				.get(`/addwithdrawStore`, {
					money: data.mobile,
					type: this.type
				})
				.then(() => {
					this.btnLoading = false;
					this.$mHelper.toast('申请成功！');
					this.$mRouter.back();
				})
				.catch(() => {
					this.btnLoading = false;
				});
		},
		async handleAddressCreate(data) {
			await this.$http
				.post(`${addressCreate}`, {
					name: data.name,
					mobile: data.mobile,
					detailAddress: data.detailAddress,
					isDefault: data.isDefault ? 1 : 0,
					provinceId: data.provinceId,
					cityId: data.cityId,
					countryId: data.countryId
				})
				.then(() => {
					this.btnLoading = false;
					this.$mHelper.toast('收货地址修改成功！');
					this.$mRouter.back();
				})
				.catch(() => {
					this.btnLoading = false;
				});
		}
	}
};
</script>

<style lang="scss">
page {
	background: $page-color-base;
}
.address-manage {
	padding-top: 16upx;
}
.rf-row-wrapper .row .tit{ width: 200rpx;}
.banner{
	height: 300rpx; border-radius: 10rpx; background-color: #eee; margin: 0 20rpx; overflow: hidden;
	image{ width: 100%;}
	swiper {
		width: 100%;
		height: 300rpx;
		swiper-item {
			image {
				width: 100%;
				height: 300rpx;
			}
		}
	}
}
</style>
